package com.byit.config;

import io.minio.MinioClient;
import io.minio.errors.InvalidEndpointException;
import io.minio.errors.InvalidPortException;
import lombok.Data;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/**
 * Minio配置
 *
 * @author wangx
 **/

@Component
@Data
@Configuration
@ConfigurationProperties(prefix = "minio")
public class MinioConfig {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    private String server;

    private String accesskey;

    private String secretkey;

    private String searchMinio;

    private String bucketName;

    //支付回调url
    private String payCallBackUrl;

    @Bean(name = "byitMinioClient")
    public MinioClient minioClient() {
        logger.info("MinioClient connection... {} ", server);
        MinioClient minioClient = null;
        try {
            minioClient = new MinioClient(server, accesskey, secretkey);
        } catch (InvalidEndpointException e) {
            logger.error("", e);
        } catch (InvalidPortException e) {
            logger.error("", e);
        }
        return minioClient;
    }
}
